<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

<spring:url value="/images/add.png" var="add"></spring:url>
<spring:url value="/images/mail.png" var="mail"></spring:url>
<spring:url value="/images/glyphicons_150_edit.png" var="edit"></spring:url>
<spring:url value="/images/" var="images"></spring:url>

<script src="${jsUrl}" type="text/javascript"></script>
<spring:url value="/js/ricerca" var="ricercajs"></spring:url>
<script src="${ricercajs}/news-ext.js"></script>
<script>

function cambiaPagDati(page){
	
	document.getElementById("pagina").value=page;
	document.getElementById("newsRicerca").submit();
}

var siteUrl = '${flowExecutionUrl}';

</script>
<div class="unit-row">
	<nav class="nav-tabs" style="width:1000px">
			<ul>
				<li><span>News</span></li>
				<li><a href="${flowExecutionUrl}&_eventId=ricerca-candidati">Ricerca Candidati</a></li>
				<li><a href="${flowExecutionUrl}&_eventId=nuovo-candidato">Nuovo Candidato</a></li>
				<li><a href="<c:url value="j_spring_security_logout" />">Logout</a></li>				
			</ul>
		</nav>
		<br />
		<c:if test="${not empty datiNewsSalvati}">
			<div class="message message-success">
				<span class="close"></span> Dati salvati con successo!
			</div>
		</c:if>
		<c:if test="${not empty emailInviata}">
			<div class="message message-success">
				<span class="close"></span> Email inviata con successo!
			</div>
		</c:if>
		<div class="unit-100 unit-centered" style="width:800px">
			<h3 class="head-toc head-toc-start">News Candidati</h3>
			<div id="emailContainer"></div>
			<form:form id="newsRicerca" cssClass="forms forms-columnar"
				action="${flowExecutionUrl}" method="POST" commandName="newsForm" >
				<form:hidden path="searched"/>
				<form:hidden path="emailHTML"  id="emailHTMLId"/>
				<form:hidden path="hideNews"  id="hideNewsId" value="false"/>
				<form:hidden path="idCandidatoToNotify"  id="idCandidatoToNotify"/>
				<form:hidden path="idNewsToHandle"  id="idNewsToHandle"/>
				<c:set var="newsList" value="${newsForm.news}" scope="session" />
 				<c:out value="${pagedBanner}" escapeXml="false"></c:out> 
				
				<table style="margin:auto;width:750px">
				<tr>
					<td>
						<table style="margin:auto;">
							<tr>
								<td style="width:25px;border:0">
									&nbsp;
								</td>
								<td style="width:200px;border:0">
									Email
								</td>	
								<td style="width:125px;border:0">
									Opportunit&agrave;
								</td>
								<td style="width:125px;border:0">
									Data arrivo
								</td>
								<td style="width:125px;border:0">
									Email
								</td>	
								<td style="width:125px;border:0">
									Gestione
								</td>
								<td style="width:125px;border:0">
									Azioni
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td colSpan="6" style="width:750px;padding-left:0px;padding-right:0px;">
						<div style="width:100%;overflow-y:scroll;height:400px;">
							<table style="text-align:left;">
								<c:forEach var="recordNews" items="${newsList}" varStatus="news" begin="0" >
									<tr>
										<td style="width:25px;border:0">
											<c:if test = "${ recordNews.mailInviata == 'S' }">						
												<img title="Mail inviata" src="${images}checkmark.png" height="24" border="0" >
											</c:if>
										</td>
										<td style="width:200px;text-align:center;padding-left:20px;padding-right:0px;">
											<c:out value="${recordNews.email}"></c:out>
										</td>
										<td style="width:125px;text-align:center;padding-left:20px;padding-right:0px;">
											<c:if test = "${ not empty  recordNews.opportunita.codice }">	
												<c:out value="${recordNews.opportunita.codice}"></c:out>/<c:out value="${recordNews.opportunita.progressivo}"></c:out>
											</c:if>
										</td>
										<td style="width:125px;text-align:center;padding-left:20px;padding-right:0px;">
											<c:out value="${recordNews.dataCreazione}"></c:out>
										</td>	
										<td style="width:125px;text-align:center;padding-left:20px;padding-right:0px;">
											<c:if test="${recordNews.gestito == 'S' && recordNews.existing }">
												<c:if test = "${ not empty recordNews.opportunita.codice}">						
													<img title="Invia Mail" src="${mail}" border="0" onclick="openEmailPopup('${recordNews.idCandidato}','${recordNews.idNews}','conOpp')">
												</c:if>
												<c:if test = "${ empty recordNews.opportunita.codice}">						
													<img title="Invia Mail" src="${mail}" border="0" onclick="openEmailPopup('${recordNews.idCandidato}','${recordNews.idNews}','senzaOpp')">
												</c:if>				
											</c:if>
										</td>	
										<td style="width:125px;text-align:center;padding-left:20px;padding-right:0px;">
											<c:if test="${recordNews.gestito == 'N'}">
												<c:choose>
													<c:when test="${recordNews.existing }">
														<a href="${flowExecutionUrl}&_eventId=aggiungiOpportunita&idCandidato=${recordNews.idCandidato}&idNews=${recordNews.idNews}">
															<img title="Aggiungi Opportunit&agrave; al Candidato" src="${edit}"  border="0">
														</a>
													</c:when>
													<c:otherwise>
														<a href="${flowExecutionUrl}&_eventId=gestisciCandidato&idCandidato=-1&emailCandidato=${recordNews.email}&idNews=${recordNews.idNews}&createFromAlfresco=true">
															<img title="Aggiungi Candidato" src="${add}" height="24" border="0">
														</a>
													</c:otherwise>
												</c:choose>
											</c:if>
										</td>
										<td style="width:125px;text-align:center;padding-left:20px;padding-right:0px;">
											<a href="${flowExecutionUrl}&_eventId=hideNews&idNewsDaCancellare=${recordNews.idNews}">
													<img alt="Elimina news" src="${images}/glyphicons_016_bin.png" border="0" />
											</a>
										</td>				
									</tr>
								</c:forEach>	
							</table>
						</div>
					</td>
				</tr>
			</table>
			
			<p class="forms-inline">
				<form:hidden id="pagina" path="pagina"/>
				<form:hidden path="recordPerPagina" />
				<input type="hidden" name="_eventId" id="eventId" value="refreshNews"> 
			</p>
		</form:form>
	</div>
	<span id="emailDiv" style="display:none"><c:out value="${templateEmail}" escapeXml="false"></c:out></span>
	
</div>